<template>
  <div class="reset-email">
    <div class="reset-email-return">
      <el-button plain icon="el-icon-back" type="text" @click="returnTo()">返回</el-button>
    </div>
    <div class="reset-email-main">
      <img src="./../assets/logo.png" draggable="false">
      <el-form :model="dynamicValidateForm" ref="dynamicValidateForm" label-width="100px" class="demo-dynamic">
        <el-form-item prop="email" :rules="[
          { required: true, message: '请输入邮箱地址', trigger: 'blur' },
          { type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] }]"
        >
          <el-input placeholder="请输入要绑定邮箱" v-model="dynamicValidateForm.email"></el-input>
        </el-form-item>
      </el-form>
      <el-button round size="medium" type="success" @click="update()">修改</el-button>
    </div>
    <div class="reset-email-power">
      © 2021 Powered by zsc ccying
    </div>
  </div>
</template>

<style>
  .reset-email-return  {
    padding-right: 600px;
  }
  .reset-email-main {
    width: 600px;
    margin: auto;
  }
  .reset-email-power {
    padding-top: 100px;
  }
</style>

<script>
  export default {
    data() {
      return {
        dynamicValidateForm: {
          email: ''
        }
      }
    },
    methods: {
      returnTo() {
        this.$router.go(-1);
      },
      update() {
        this.$http({
          method: 'post',
          url: '/reset-email',
          data: this.$qs.stringify({
            email: this.dynamicValidateForm.email
          })
        }).then(res=>{
          let {code:code, data:data} = res.data;
          if (code === 200) {
            var user = JSON.stringify(data);
            sessionStorage.setItem('user', user);
            alert("成功")
            this.$router.go(-2);
          }
        })
      }
    }
  }
</script>
